home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Utilities / Winter Shell 1.0d2 / Source / Libraries / ExceptionLib / ExceptionLib.c next >
Encoding:
C/C++ Source or Header  |  1994-01-19  |  2.1 KB  |  109 lines  |  [TEXT/KAHL]

  1. /* Exception handling.
  2.  
  3.     94/01/19 aih - defined ExceptionTryType in ExceptionLib.h
  4.                      - added some comments to ExceptionLib.h
  5.     94/01/12 aih - added a few functions for setting information describing
  6.                         a failure
  7.     94/01/10 aih - made exception data a global variable
  8.     93/11/16 aih - fixed an error in the setup code which didn't properly
  9.                         reset gExecetion.jmpenv after a failure
  10.                      - added a comment describing a _try structure
  11.     93/10/26 aih - simplified macros a bit, fixed bug with prior bug fix...
  12.     93/10/23 aih - fixed bug with recursive failures/retries
  13.     93/10/19 aih - improved error reporting
  14.     93/03/?? aih - created */
  15.  
  16. #include <string.h>
  17. #include <PrintTraps.h>
  18. #include "ErrorLib.h"
  19. #include "ExceptionLib.h"
  20.  
  21. ExceptionType gException; /* information about current exception */
  22.  
  23. void FailActionSet(short action)
  24. {
  25.     gException.action = action;
  26. }
  27.  
  28. void FailObjectSet(const CStr255 object)
  29. {
  30.     *gException.object = 0;
  31.     if (object)
  32.         strcpy(gException.object, object);
  33. }
  34.  
  35. void FailExplanationSet(const CStr255 explanation)
  36. {
  37.     *gException.explanation = 0;
  38.     if (explanation)
  39.         strcpy(gException.explanation, explanation);
  40. }
  41.  
  42. void FailInfoSet(short action, const CStr255 object, const CStr255 explanation)
  43. {
  44.     FailActionSet(action);
  45.     FailObjectSet(object);
  46.     FailExplanationSet(explanation);
  47. }
  48.  
  49. void FailInfoClear(void)
  50. {
  51.     FailInfoSet(0, NULL, NULL);
  52. }
  53.  
  54. void FailClear(void)
  55. {
  56.     gException.err = noErr;
  57.     FailInfoClear();
  58. }
  59.  
  60. void FailDisplay(void)
  61. {
  62.     if (gException.err != userCanceledErr) {
  63.         ErrorDisplay(gException.err, gException.action,
  64.             gException.object, gException.explanation);
  65.     }
  66. }
  67.  
  68. OSErr FailReason(void)
  69. {
  70.     return(gException.err);
  71. }
  72.  
  73. void FailOSErr(OSErr err)
  74. {
  75.     if (err) {
  76.         if (err == iPrAbort)
  77.             err = userCanceledErr;
  78.         if (! gException.err)
  79.             gException.err = err;
  80.         RAISE;
  81.     }
  82. }
  83.  
  84. void FailMemError(void)
  85. {
  86.     FailOSErr(MemError());
  87. }
  88.  
  89. void FailResError(void)
  90. {
  91.     FailOSErr(ResError());
  92. }
  93.  
  94. void FailPrError(void)
  95. {
  96.     FailOSErr(PrError());
  97. }
  98.  
  99. void FailNIL(void *p)
  100. {
  101.     if (! p) FailOSErr(MemError() ? MemError() : memFullErr);
  102. }
  103.  
  104. void FailNILRes(void *p)
  105. {
  106.     if (! p) FailOSErr(ResError() ? ResError() : resNotFound);
  107. }
  108.  
  109.